from ipyleaflet import Map, GeoJSON, Marker, Popup
import json
import requests

# 1. 获取亚洲国家GeoJSON数据（自然地球数据集）
url = "https://raw.githubusercontent.com/johan/world.geo.json/master/continents/asia.geojson"
response = requests.get(url)
asia_geojson = response.json()

# 2. 亚洲国家首都数据（示例，实际应用建议用完整数据集）
capitals = {
    "China": {"capital": "Beijing", "coords": [39.9042, 116.4074]},
    "Japan": {"capital": "Tokyo", "coords": [35.6762, 139.6503]},
    "India": {"capital": "New Delhi", "coords": [28.6139, 77.2090]},
    "Russia": {"capital": "Moscow", "coords": [55.7558, 37.6173]},  # 欧洲部分首都
    "Indonesia": {"capital": "Jakarta", "coords": [-6.2088, 106.8456]},
    "Pakistan": {"capital": "Islamabad", "coords": [33.6844, 73.0479]},
    "Turkey": {"capital": "Ankara", "coords": [39.9334, 32.8597]},
    "Iran": {"capital": "Tehran", "coords": [35.6892, 51.3890]},
    "Thailand": {"capital": "Bangkok", "coords": [13.7563, 100.5018]},
    "Vietnam": {"capital": "Hanoi", "coords": [21.0278, 105.8342]}
    # 可继续添加其他国家...
}

# 3. 创建地图（居中在亚洲）
m = Map(
    center=[30, 100],
    zoom=4,
    basemap=basemaps.Esri.WorldTopoMap  # 使用地形图底图
)

# 4. 添加亚洲国家边界
asia_layer = GeoJSON(
    data=asia_geojson,
    style={
        'color': 'blue',
        'opacity': 1,
        'weight': 1.5,
        'fillOpacity': 0.1
    },
    hover_style={
        'fillColor': '#ff0000',
        'fillOpacity': 0.7
    },
    name="Asian Countries"
)
m.add_layer(asia_layer)

# 5. 标注首都
for country, info in capitals.items():
    marker = Marker(
        location=info["coords"],
        draggable=False,
        title=f"{country}: {info['capital']}",
        popup=Popup(child=f"<b>{info['capital']}</b><br>Capital of {country}")
    )
    m.add_layer(marker)

# 6. 添加图层控制（可选）
m.add_control(LayersControl())

# 显示地图
m
